<?php
/**
 * This file handles the retrieval and serving of login, register and reminder password functionality
 * @author adrian
 *
 */
class Login_Controller_Login {
	/**
	 * This template variable will hold the 'view; portion of our MVC for this controller
	 */
	public $template = "./login/views/login.php";
	
	/**
	 * This is the default function that will be called by router.php
	 * 
	 * @param array $getVars
	 * @param array $postVars
	 */
	public function main(array $getVars, array $postVars){
	
		$loginModel = new Login_Model_Login;
		
		// get an data, go to application logic
		$article = $loginModel->getPage($getVars['page'], $postVars);
		if(isset($article['sessionValues'])){
			$_SESSION = $article['sessionValues'];
		}
		if(isset($getVars['page']) && ($getVars['page'] == "logout")){
			unset($_SESSION);
			session_destroy();
			echo '<meta http-equiv="Refresh" content="0;url='.SERVER_ROOT.'?login&page=login">';
		}
		if($_SESSION['users_access_level'] > 0){
			$getVars['page'] = "logged";
		}
		$loginModel = new Login_Model_Login;
		
		// get an data, go to application logic
		$article = $loginModel->getPage($getVars['page'], $postVars);
		if(isset($article['sessionValues'])){
			$_SESSION = $article['sessionValues'];
		}
		/**
		 * create a new view and pass it our template
		 */
		$view = new Core_Model_View($this->template);
		/**
		 * assign article data to view 
		 */
		$view->assign('article', $article);
	}
}